﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace G.Controls
{
    public class TileControl : ButtonBase
    {
        public static readonly DependencyProperty CountProperty = DependencyProperty.Register("Count", typeof(string), typeof(TileControl), new PropertyMetadata(null, CountPropertyChanged));

        static void CountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TileControl control = d as TileControl;
            control.SetGridCountVisible();
        }


        public string Count
        {
            get
            {
                return (string)this.GetValue(CountProperty);
            }
            set
            {
                this.SetValue(CountProperty, value);
            }
        }

        public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(TileControl), null);

        public ImageSource Source
        {
            get { return (ImageSource)GetValue(SourceProperty); }
            set { SetValue(SourceProperty, value); }
        }




        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(TileControl), null);

        public string Title
        {
            get
            {
                return this.GetValue(TitleProperty) as string;
            }
            set
            {
                this.SetValue(TitleProperty, value);
            }
        }
        private void SetGridCountVisible()
        {
            if (Grid_Count != null)
            {
                if (string.IsNullOrEmpty(this.Count))
                    Grid_Count.Visibility = System.Windows.Visibility.Collapsed;
                else
                    Grid_Count.Visibility = System.Windows.Visibility.Visible;
            }
        }
        Grid Grid_Count;
        public TileControl()
        {
            this.DefaultStyleKey = typeof(TileControl);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            Grid_Count = this.GetTemplateChild("Grid_Count") as Grid;
            SetGridCountVisible();
        }
    }
}
